package com.example.com.skills_utf8;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SearchView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.utils.Utils1;

public class Theme26Activity extends Activity{

	Theme26Activity activity = this;
	private SpinnerAdapter mSpinnerAdapter;
	
	private Spinner mSpinner;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	//	setTheme(android.R.style.Theme_Holo_NoActionBar);
		setTheme(android.R.style.Theme_Holo);
		setContentView(R.layout.activity_theme26);

		
		mSpinner = (Spinner)findViewById(R.id.spinner);
		
		
		/*1  OK
		mSpinnerAdapter = ArrayAdapter.createFromResource(
				this, 
				R.array.fruit, 
				android.R.layout.simple_spinner_dropdown_item);
		
		ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
		actionBar.setListNavigationCallbacks(mSpinnerAdapter,  new OnNavigationListener() {
			
			@Override
			public boolean onNavigationItemSelected(int itemPosition, long itemId) {
				// TODO Auto-generated method stub
				return false;
			}
		});
		1*/
		
		
	}
	
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		
		 // Inflate the menu items for use in the action bar
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.action_menu, menu);
		
	   
	    
	    // 搜索
	    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
	    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
	        @Override
	        public boolean onQueryTextSubmit(String s) {
	            Utils1.showToastShort(activity, s);
	            return true;
	        }
	 
	        @Override
	        public boolean onQueryTextChange(String s) {
	            return false;
	        }
	    });
	    
		
		return super.onCreateOptionsMenu(menu);
	}
	
	
	
	PopupWindow mPopupWindow;
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		
		
		if(item.getItemId() == R.id.action_settings){
			View mPopView = LayoutInflater.from(activity).inflate(
					R.layout.popupwindow_theme26, null);

			ListView mPopDisplay=(ListView)mPopView
					.findViewById(R.id.home_popupwindow_display);
			PopupWindowAdapter adapter = new PopupWindowAdapter();
			mPopDisplay.setAdapter(adapter);
			if (mPopupWindow == null) {
				mPopupWindow = new PopupWindow(mPopView, 200,
						LayoutParams.WRAP_CONTENT, true);
				mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); 
			}
			if (mPopupWindow.isShowing()) {
				mPopupWindow.dismiss();
			} else {
				mPopupWindow.showAsDropDown(mSpinner, 0, 0);
			}
			mPopDisplay.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
						long arg3) {
					mPopupWindow.dismiss();
					
					
					
					
				}
			});
			
		}
		
		
		return super.onOptionsItemSelected(item);
	}
	
	
	
	
	
	
	
	
	private class PopupWindowAdapter extends BaseAdapter {

		public int getCount() {
			return 5;
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = new TextView(activity);
			}
			return convertView;
		}

		
	}
	
	
}
